package com.android.kotlincoroutinemvvmdemo.view
import android.content.Context
import android.graphics.Canvas
import android.graphics.Paint
import android.graphics.Path
import android.util.AttributeSet
import com.android.kotlincoroutinemvvmdemo.R

/*
* AccountView
* */
class AccountView @JvmOverloads constructor(
    context: Context,
    attributeSet: AttributeSet? = null
) : BaseView(context, attributeSet) {

    private val mStrokeWidth = context.resources.getDimension(R.dimen.dp_2)

    private val mPaint0 by lazy {
        Paint().apply {
            isAntiAlias = true
            isDither = true
            strokeWidth = mStrokeWidth
            style = Paint.Style.STROKE
            color = context.resources.getColor(R.color.color_5FD534)
        }
    }

    private val mPaint1 by lazy {
        Paint().apply {
            isAntiAlias = true
            isDither = true
            color = context.resources.getColor(R.color.color_A0BFF1AD)
        }
    }

    private val mPath0 by lazy {
        Path()
    }

    override fun onDraw(canvas: Canvas?) {
        super.onDraw(canvas)
        canvas?.apply {
            val cx = mWidth.toFloat() / 2
            val cy = mHeight.toFloat() / 2
            translate(cx, cy)

            drawCircle(
                0F,
                0F,
                cx,
                mPaint1
            )

            mPath0.apply {
                arcTo(
                    -cx * 2 / 3,
                    0F,
                    cx * 2 / 3,
                    cy * 4 / 3,
                    180F,
                    180F,
                    true
                )
            }
            drawPath(mPath0, mPaint0)

            drawCircle(
                0F,
                -cy * 3 / 12,
                cx * 3 / 12,
                mPaint0
            )
        }
    }
}